package hot100;

import java.util.Arrays;

public class Solution43 {
    public String multiply(String num1, String num2) {
        int m = num1.length();
        int n = num2.length();
        int[] num = new int[m + n];
        for (int i = m - 1; i >= 0; i--) {
            for (int j = n - 1; j >= 0; j--) {
                num[i + j + 1] += (num1.charAt(i) - '0') * (num2.charAt(j) - '0');
            }
        }
        for (int i = m + n - 1; i > 0; i--) {
            num[i - 1] += num[i] / 10;
            num[i] %= 10;
        }
        int index = num[0] == 0 ? 1 : 0;
        StringBuilder ans = new StringBuilder();
        while (index < m + n) {
            ans.append(num[index]);
            index++;
        }
        return ans.toString();
    }


    public static void main(String[] args) {
        Solution43 solution43 = new Solution43();
        System.out.println(solution43.multiply("123", "456"));
    }
}
